package com.mob.tools.gui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.widget.ImageView;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import com.mob.tools.utils.BitmapHelper;

public class ScaledImageView extends ImageView
  implements View.OnTouchListener
{
  private static final int DRAG_1 = 1;
  private static final int DRAG_2 = 2;
  private static final int NONE = 0;
  private static final int ZOOM = 3;
  private Bitmap bitmap;
  private float distSquare;
  private float[] downPoint;
  private int dragScrollMinDistSquare;
  private OnMatrixChangedListener listener;
  private Matrix matrix;
  private int mode;
  private Matrix savedMatrix;

  public ScaledImageView(Context paramContext)
  {
    super(paramContext);
    init(paramContext);
  }

  public ScaledImageView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init(paramContext);
  }

  public ScaledImageView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    init(paramContext);
  }

  private void init(Context paramContext)
  {
    this.dragScrollMinDistSquare = ViewConfiguration.get(paramContext).getScaledTouchSlop();
    this.dragScrollMinDistSquare *= this.dragScrollMinDistSquare;
    setOnTouchListener(this);
  }

  public Bitmap getCropedBitmap(Rect paramRect)
  {
    try
    {
      Bitmap localBitmap1 = BitmapHelper.captureView(this, getWidth(), getHeight());
      if (localBitmap1 == null)
      {
        MobLog.getInstance().w("ivPhoto.getDrawingCache() returns null", new Object[0]);
        return null;
      }
      Bitmap localBitmap2 = Bitmap.createBitmap(localBitmap1, paramRect.left, paramRect.top, paramRect.width(), paramRect.height());
      localBitmap1.recycle();
      return localBitmap2;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return null;
  }

  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    try
    {
      switch (paramMotionEvent.getAction())
      {
      case 0:
        this.matrix = new Matrix();
        this.matrix.set(getImageMatrix());
        this.savedMatrix = new Matrix();
        this.savedMatrix.set(this.matrix);
        float[] arrayOfFloat12 = new float[2];
        arrayOfFloat12[0] = paramMotionEvent.getX(0);
        arrayOfFloat12[1] = paramMotionEvent.getY(0);
        this.downPoint = arrayOfFloat12;
      case 1:
        for (this.mode = 1; ; this.mode = 0)
        {
          setImageMatrix(this.matrix);
          break;
          if (this.listener != null)
            this.listener.onMactrixChage(this.matrix);
          float f9 = paramMotionEvent.getX(0) - this.downPoint[0];
          float f10 = paramMotionEvent.getY(0) - this.downPoint[1];
          if ((this.mode == 1) && (f9 * f9 + f10 * f10 <= this.dragScrollMinDistSquare))
            performClick();
        }
      case 5:
      case 6:
      case 261:
      case 262:
      case 2:
      }
    }
    catch (Throwable localThrowable)
    {
      while (true)
      {
        MobLog.getInstance().w(localThrowable);
        break;
        float[] arrayOfFloat10 = new float[2];
        arrayOfFloat10[0] = paramMotionEvent.getX(0);
        arrayOfFloat10[1] = paramMotionEvent.getY(0);
        float[] arrayOfFloat11 = new float[2];
        arrayOfFloat11[0] = paramMotionEvent.getX(1);
        arrayOfFloat11[1] = paramMotionEvent.getY(1);
        float f7 = arrayOfFloat10[0] - arrayOfFloat11[0];
        float f8 = arrayOfFloat10[1] - arrayOfFloat11[1];
        this.distSquare = (f7 * f7 + f8 * f8);
        this.mode = 3;
        continue;
        float[] arrayOfFloat9 = new float[2];
        arrayOfFloat9[0] = paramMotionEvent.getX(1);
        arrayOfFloat9[1] = paramMotionEvent.getY(1);
        this.downPoint = arrayOfFloat9;
        this.savedMatrix.set(this.matrix);
        this.mode = 2;
        continue;
        float[] arrayOfFloat7 = new float[2];
        arrayOfFloat7[0] = paramMotionEvent.getX(0);
        arrayOfFloat7[1] = paramMotionEvent.getY(0);
        float[] arrayOfFloat8 = new float[2];
        arrayOfFloat8[0] = paramMotionEvent.getX(1);
        arrayOfFloat8[1] = paramMotionEvent.getY(1);
        float f5 = arrayOfFloat7[0] - arrayOfFloat8[0];
        float f6 = arrayOfFloat7[1] - arrayOfFloat8[1];
        this.distSquare = (f5 * f5 + f6 * f6);
        this.mode = 3;
        continue;
        float[] arrayOfFloat6 = new float[2];
        arrayOfFloat6[0] = paramMotionEvent.getX(0);
        arrayOfFloat6[1] = paramMotionEvent.getY(0);
        this.downPoint = arrayOfFloat6;
        this.savedMatrix.set(this.matrix);
        this.mode = 1;
        continue;
        if (this.mode == 1)
        {
          float[] arrayOfFloat5 = new float[2];
          arrayOfFloat5[0] = paramMotionEvent.getX(0);
          arrayOfFloat5[1] = paramMotionEvent.getY(0);
          this.matrix.set(this.savedMatrix);
          this.matrix.postTranslate(arrayOfFloat5[0] - this.downPoint[0], arrayOfFloat5[1] - this.downPoint[1]);
        }
        else if (this.mode == 2)
        {
          float[] arrayOfFloat4 = new float[2];
          arrayOfFloat4[0] = paramMotionEvent.getX(1);
          arrayOfFloat4[1] = paramMotionEvent.getY(1);
          this.matrix.set(this.savedMatrix);
          this.matrix.postTranslate(arrayOfFloat4[0] - this.downPoint[0], arrayOfFloat4[1] - this.downPoint[1]);
        }
        else if (this.mode == 3)
        {
          float[] arrayOfFloat1 = new float[2];
          arrayOfFloat1[0] = paramMotionEvent.getX(0);
          arrayOfFloat1[1] = paramMotionEvent.getY(0);
          float[] arrayOfFloat2 = new float[2];
          arrayOfFloat2[0] = paramMotionEvent.getX(1);
          arrayOfFloat2[1] = paramMotionEvent.getY(1);
          float f1 = arrayOfFloat1[0] - arrayOfFloat2[0];
          float f2 = arrayOfFloat1[1] - arrayOfFloat2[1];
          float f3 = f1 * f1 + f2 * f2;
          this.matrix.set(this.savedMatrix);
          float f4 = (float)Math.sqrt(f3 / this.distSquare);
          float[] arrayOfFloat3 = new float[2];
          arrayOfFloat3[0] = ((arrayOfFloat1[0] + arrayOfFloat2[0]) / 2.0F);
          arrayOfFloat3[1] = ((arrayOfFloat1[1] + arrayOfFloat2[1]) / 2.0F);
          this.matrix.postScale(f4, f4, arrayOfFloat3[0], arrayOfFloat3[1]);
        }
      }
      return false;
    }
    return true;
  }

  public void rotateLeft()
  {
    try
    {
      this.matrix = new Matrix();
      float[] arrayOfFloat1 = { 0.0F, 1.0F, 0.0F, -1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F };
      this.matrix.setValues(arrayOfFloat1);
      Bitmap localBitmap = Bitmap.createBitmap(this.bitmap, 0, 0, this.bitmap.getWidth(), this.bitmap.getHeight(), this.matrix, true);
      if ((localBitmap != null) && (!localBitmap.isRecycled()))
      {
        this.bitmap.recycle();
        this.bitmap = localBitmap;
      }
      setImageBitmap(this.bitmap);
      this.matrix = new Matrix();
      this.matrix.set(getImageMatrix());
      this.matrix.getValues(arrayOfFloat1);
      int[] arrayOfInt = new int[2];
      arrayOfInt[0] = getWidth();
      arrayOfInt[1] = getHeight();
      float[] arrayOfFloat2 = new float[2];
      arrayOfFloat1[0] *= this.bitmap.getWidth();
      arrayOfFloat2[1] = (arrayOfFloat1[4] * this.bitmap.getHeight());
      float[] arrayOfFloat3 = new float[2];
      arrayOfFloat3[0] = ((arrayOfInt[0] - arrayOfFloat2[0]) / 2.0F);
      arrayOfFloat3[1] = ((arrayOfInt[1] - arrayOfFloat2[1]) / 2.0F);
      arrayOfFloat1[2] = arrayOfFloat3[0];
      arrayOfFloat1[5] = arrayOfFloat3[1];
      this.matrix.setValues(arrayOfFloat1);
      if (this.listener != null)
        this.listener.onMactrixChage(this.matrix);
      setImageMatrix(this.matrix);
      return;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
  }

  public void rotateRight()
  {
    try
    {
      this.matrix = new Matrix();
      float[] arrayOfFloat1 = { 0.0F, -1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F };
      this.matrix.setValues(arrayOfFloat1);
      Bitmap localBitmap = Bitmap.createBitmap(this.bitmap, 0, 0, this.bitmap.getWidth(), this.bitmap.getHeight(), this.matrix, true);
      if ((localBitmap != null) && (!localBitmap.isRecycled()))
      {
        this.bitmap.recycle();
        this.bitmap = localBitmap;
      }
      setImageBitmap(this.bitmap);
      this.matrix = new Matrix();
      this.matrix.set(getImageMatrix());
      this.matrix.getValues(arrayOfFloat1);
      int[] arrayOfInt = new int[2];
      arrayOfInt[0] = getWidth();
      arrayOfInt[1] = getHeight();
      float[] arrayOfFloat2 = new float[2];
      arrayOfFloat1[0] *= this.bitmap.getWidth();
      arrayOfFloat2[1] = (arrayOfFloat1[4] * this.bitmap.getHeight());
      float[] arrayOfFloat3 = new float[2];
      arrayOfFloat3[0] = ((arrayOfInt[0] - arrayOfFloat2[0]) / 2.0F);
      arrayOfFloat3[1] = ((arrayOfInt[1] - arrayOfFloat2[1]) / 2.0F);
      arrayOfFloat1[2] = arrayOfFloat3[0];
      arrayOfFloat1[5] = arrayOfFloat3[1];
      this.matrix.setValues(arrayOfFloat1);
      if (this.listener != null)
        this.listener.onMactrixChage(this.matrix);
      setImageMatrix(this.matrix);
      return;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
  }

  public void setBitmap(Bitmap paramBitmap)
  {
    this.bitmap = paramBitmap;
    setImageBitmap(paramBitmap);
    int[] arrayOfInt1 = new int[2];
    arrayOfInt1[0] = getWidth();
    arrayOfInt1[1] = getHeight();
    int[] arrayOfInt2 = new int[2];
    arrayOfInt2[0] = this.bitmap.getWidth();
    arrayOfInt2[1] = this.bitmap.getHeight();
    int[] arrayOfInt3 = BitmapHelper.fixRect(arrayOfInt2, arrayOfInt1);
    int[] arrayOfInt4 = new int[2];
    arrayOfInt4[0] = ((arrayOfInt1[0] - arrayOfInt3[0]) / 2);
    arrayOfInt4[1] = ((arrayOfInt1[1] - arrayOfInt3[1]) / 2);
    float[] arrayOfFloat = new float[2];
    arrayOfFloat[0] = (arrayOfInt3[0] / arrayOfInt2[0]);
    arrayOfFloat[1] = (arrayOfInt3[1] / arrayOfInt2[1]);
    this.matrix = new Matrix();
    this.matrix.set(getImageMatrix());
    this.matrix.postScale(arrayOfFloat[0], arrayOfFloat[1]);
    this.matrix.postTranslate(arrayOfInt4[0], arrayOfInt4[1]);
    if (this.listener != null)
      this.listener.onMactrixChage(this.matrix);
    setImageMatrix(this.matrix);
  }

  public void setOnMatrixChangedListener(OnMatrixChangedListener paramOnMatrixChangedListener)
  {
    this.listener = paramOnMatrixChangedListener;
    if (this.matrix != null)
    {
      if (this.listener != null)
        this.listener.onMactrixChage(this.matrix);
      setImageMatrix(this.matrix);
    }
  }

  public void zoomIn()
  {
    this.matrix = new Matrix();
    this.matrix.set(getImageMatrix());
    this.matrix.postScale(1.072F, 1.072F);
    if (this.listener != null)
      this.listener.onMactrixChage(this.matrix);
    setImageMatrix(this.matrix);
  }

  public void zoomOut()
  {
    this.matrix = new Matrix();
    this.matrix.set(getImageMatrix());
    this.matrix.postScale(0.933F, 0.933F);
    if (this.listener != null)
      this.listener.onMactrixChage(this.matrix);
    setImageMatrix(this.matrix);
  }

  public static abstract interface OnMatrixChangedListener
  {
    public abstract void onMactrixChage(Matrix paramMatrix);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.gui.ScaledImageView
 * JD-Core Version:    0.6.2
 */